package com.kuaiprint.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.kuaiprint.bean.PrintStoreBean;
import com.kuaiprint.main.R;

public class ListViewAdapter extends BaseAdapter {


	
	    private LayoutInflater inflater;   
	    private Context mContext;  
	    private List<PrintStoreBean> list;
	  
	    public ListViewAdapter (Context context,List<PrintStoreBean> list)
	    {
	    	this.mContext = context;
	    	this.inflater = LayoutInflater.from(mContext);
	    	this.list=list;
	    }
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		 ViewHolder holder;
		if(convertView == null)
		{
			convertView=inflater.inflate(R.layout.printstore_item, null);
			 holder = new ViewHolder();
			 holder.printStoreName = (TextView) convertView.findViewById(R.id.print_store_name);
			 holder.printStoreDes = (TextView) convertView.findViewById(R.id.print_store_des);
			 holder.printStoreDis = (TextView) convertView.findViewById(R.id.print_store_dis);
			 holder.printStoreImg = (ImageView) convertView.findViewById(R.id.print_store_img);
			 
			
			 convertView.setTag(holder);
		}
		else
		{
			 holder = (ViewHolder)convertView.getTag();
		}
		
		PrintStoreBean store = list.get(position);
		holder.printStoreName.setText(store.getPrintStoreName());
		//holder.printStoreDes.setText(store.getPrintStoreDes());
		//holder.printStoreDis.setText(store.getPrintStoreDis());
		
		convertView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(mContext, "click"+position, Toast.LENGTH_SHORT).show();
			}
		});
		
		
		return convertView;
	}

	static class ViewHolder {

		TextView printStoreName;
		ImageView printStoreImg;
		TextView printStoreDes;
		TextView printStoreDis;

	}

	

}
